package leetcode.jianzhioffer;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-31 17:47
 **/
public class JianZhiOffer42 {

    public int maxSubArray(int[] nums) {
        int f = nums[0];
        int max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            f = Math.max(f + nums[i], nums[i]);
            max = Math.max(f, max);
        }
        return max;
    }

    public static void main(String[] args) {
        JianZhiOffer42 offer = new JianZhiOffer42();
        offer.maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4});
    }

}
